<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class WarehousesOut extends Model
{
    use HasFactory;

    protected $fillable = ['title','warehouse_id','project_id','user_id','out_date','quantity','numbers','reviewer_id','review_date','review_comment','status'];

    const POSTONLY = ['title','warehouse_id','project_id','user_id','out_date','quantity','numbers','reviewer_id','review_date','review_comment','status'];

    protected function serializeDate(\DateTimeInterface $date)
    {
        return $date->format($this->dateFormat ?: 'Y-m-d H:i:s');
    }

    public function application()
    {
        return $this->hasOne(Application::class,'source_id','id')->where('model','WarehousesOut')->orderBy('id','desc');
    }

    public function warehouse()
    {
        return $this->hasOne(Warehouse::class,'id','warehouse_id')->select('id','title','sum');
    }

    public function user()
    {
        return $this->hasOne(User::class,'id','user_id')->select('id','name');
    }
}
